home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / general / _setjmp.c next >
C/C++ Source or Header  |  1995-12-23  |  2KB  |  73 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * the Systems Programming Group of the University of Utah Computer
  7.  * Science Department.
  8.  *
  9.  * Redistribution and use in source and binary forms are permitted
  10.  * provided that: (1) source distributions retain this entire copyright
  11.  * notice and comment, and (2) distributions including binaries display
  12.  * the following acknowledgement:  ``This product includes software
  13.  * developed by the University of California, Berkeley and its contributors''
  14.  * in the documentation or other materials provided with the distribution
  15.  * and in all advertising materials mentioning features or use of this
  16.  * software. Neither the name of the University nor the names of its
  17.  * contributors may be used to endorse or promote products derived
  18.  * from this software without specific prior written permission.
  19.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  21.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  22.  */
  23.  
  24. /*
  25.  * C library -- _setjmp, _longjmp
  26.  *
  27.  *    _longjmp(a,v)
  28.  * will generate a "return(v)" from
  29.  * the last call to
  30.  *    _setjmp(a)
  31.  * by restoring registers from the stack,
  32.  * The previous signal state is NOT restored.
  33.  */
  34.  
  35. #include "defs.h"
  36.  
  37. ENTRY(_setjmp)
  38. asm("
  39.     movl    sp@(4),a0    /* save area pointer */
  40.     clrl    a0@+        /* no old onstack */
  41.     clrl    a0@+        /* no old sigmask */
  42.     movl    sp,a0@+        /* save old SP */
  43.     movl    a5,a0@+        /* save old FP */
  44.     clrl    a0@+        /* no old AP */
  45.     movl    sp@,a0@+    /* save old PC */
  46.     clrl    a0@+        /* clear PS */
  47.     moveml    d2-d7/a2-a4/a6,a0@    /* save other non-scratch regs */
  48.     clrl    d0        /* return zero */
  49.     rts
  50. ");
  51.  
  52. ENTRY(_longjmp)
  53. asm("
  54.     movl    sp@(4),a0    /* save area pointer */
  55.     addql    #8,a0        /* skip onstack/sigmask */
  56.     tstl    a0@        /* ensure non-zero SP */
  57.     jeq    Botch        /* oops! */
  58.     movl    sp@(8),d0    /* grab return value */
  59.     jne    Ok        /* non-zero ok */
  60.     moveq    #1,d0        /* else make non-zero */
  61. Ok:
  62.     movl    a0@+,sp        /* restore SP */
  63.     movl    a0@+,a5        /* restore FP */
  64.     addql    #4,a0        /* skip AP */
  65.     movl    a0@+,sp@    /* restore PC */
  66.     moveml    a0@(4),d2-d7/a2-a4/a6    /* restore non-scratch regs */
  67.     rts
  68.  
  69. Botch:
  70.     jsr    _longjmperror
  71.     stop    #0
  72. ");
  73.